package com.yunji.web.message;

import com.yunji.base.business.SuggestBusiness;
import com.yunji.base.domain.SuggestDO;
import com.yunji.base.dto.SuggestReadDTO;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.model.params.SuggestParam;
import com.yunji.common.model.vo.SuggestVO;
import com.yunji.common.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.web.message
 * @Title: SuggestController
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-10-30 17:41:51      V1.0        HuaAo       新建类
 */
@RestController
@Api(tags = "管理端-建议管理")
@RequestMapping("/container/suggest")
public class SuggestController {

    @Resource
    SuggestBusiness business;

    @Resource
    protected HttpServletResponse response;

    @ApiOperation("建议列表")
    @GetMapping("/list")
    public Response<List<SuggestVO>> list(@Valid SuggestParam param) {
        return ResponseHelper.successWithPage(business.search(param), param.getTotal());
    }

    @ApiOperation("导出列表")
    @PostMapping("/export")
    public void export(SuggestParam param) {
        List<SuggestDO> list = business.export(param);
        ExcelUtil<SuggestDO> util = new ExcelUtil<>(SuggestDO.class);
        util.exportExcel(response, list, "反馈列表");
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/delete/{ids}")
    public Response<?> delete(@PathVariable List<Long> ids) {
        return ResponseHelper.handle(business.delete(ids), "删除失败");
    }


    @PutMapping("/operateRead")
    @ApiOperation("操作已读未读")
    public Response<?> operateRead(@Valid @RequestBody SuggestReadDTO dto) {
        return ResponseHelper.handle(business.operateRead(dto), "操作失败");
    }

    /*------------------------------------------搜索栏-----------------------------------------------*/

    @ApiOperation("用户昵称匹配搜索")
    @GetMapping("/searchUserName")
    public Response<?> searchUserName(@RequestParam("userName") String userName) {
        return ResponseHelper.success(business.searchUserName(userName));
    }

    @ApiOperation("手机号匹配搜索")
    @GetMapping("/searchPhoneNumber")
    public Response<?> searchPhoneNumber(@RequestParam("phoneNumber") String phoneNumber) {
        return ResponseHelper.success(business.searchPhoneNumber(phoneNumber));
    }

}